import { createSlice, createAsyncThunk } from '@reduxjs/toolkit'
import { getDoctorList } from '../../utils/api'
const doctorSlice = createSlice({
    name: 'doctor',
    initialState: {
        doctorList: [] as DoctorRowType[]
    },
    reducers: {
        // 初始化doctorList
        doctorListInit(state, action) {
            state.doctorList = action.payload
        }
    }
})
const { doctorListInit } = doctorSlice.actions
// 请求医生列表数据
export const getDoctorListThunk = createAsyncThunk('getDoctorListThunk', async (bus_id: string | undefined, { dispatch }) => {
    const { data } = await getDoctorList({ bus_id })
    if (data.code === 200) {
        // @ts-ignore
        dispatch(doctorListInit(data.data))
    }
})
const doctorReducer = doctorSlice.reducer
export default doctorReducer